// @/views/refPage/components/son.tsx 文件路径

import React, { useState,forwardRef,useImperativeHandle } from 'react'
import '../index.less'
const Son = (props:any,ref:any) => {
  const [refStr,setRefStr] = useState(0)
  const changeStr = (num:number)=>{
    setRefStr(num)
  }
  // 暴露方法给父组件
  useImperativeHandle(ref, () => {
    return {
      changeStr
    };
  });
  return (
    <div>
      看看父组件如何获取我的方法：{refStr}
    </div>
  )
}
// 使用forwardRef对子组件的导出进行包装，让父组件可以通过ref获取到我
export default forwardRef(Son)